<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>天线</title>
</head>
<body>
<section>
    <div>
        <div class="layui-card">
            <div class="layui-card-body">
                <div>
                    <button ADP_BTN method="addEntity"><i class="layui-icon layui-icon-add-circle-fine"></i>增加</button>
                    <button adp_btn method="deleteAllEntity"><i class="layui-icon layui-icon-close"></i>删除</button>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="adp-content">
                <form id="queryForm"></form>
                <table id="queryTable"></table>
            </div>
        </div>
    </div>
</section>
<div style="width: 600px;display: none;" id="mergeFormDiv">
    <form action="" method="post" id="mergeForm" class="adp-center"></form>
</div>
</body>
</html>

<script src="../static/adp/import.js"></script>

<script type="text/html" id="OPERATION_ROW_TPL">
    <a class="layui-btn layui-btn-sm" lay-event="edit"> <i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i
            class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script type="text/javascript">
    var queryform = $("#queryForm").adpForm({
        elem: [{type: "text", label: "阅读器IP", name: "ip", placeholder: "请输入阅读器IP"},
            {type: "text", label: "接口", name: "connect", placeholder: "请输入天线所在接口"},
            {type: "text", label: "工位", name: "location", placeholder: "请输入工位"},
            {type: "text", label: "天线类型", name:"antType", placeholder: "请输入天线类型"}],
        button: [{type: "submit", label: "查询", method: "query", icon: 'query'}, {type: "reset", label: "重置"}],
        methods: {
            query: function query(data) {
                queryTable.reload(data);
            }
        }
    });

    var mergeForm = $("#mergeForm").adpForm({
        layout: 'vertical',
        elem: [
            {type: "text", label: "阅读器IP", name: "ip", verify: "required", placeholder: "请输入阅读器IP"},
            {type: "text", label: "接口", name: "connect", verify: "required", placeholder: "必须为1-4的纯数字"},
            {type: "text", label: "工位", name: "location", verify: "required", placeholder: "请输入工位"},
            {type: "text", label: "天线类型", name: "antType", verify: "required", placeholder: "请输入天线类型"},
            {type: "hidden", name: "id"}
        ],
        button: [
            {type: "submit", label: "保存", method: "submit"},
            {type: "reset", label: "重置"}
        ],
        methods: {
            submit: function submit(data) {
                var isNull = SV("Ant")("save")(data);
                if (null == isNull) {
                    alert("阅读器不存在");
                }else{
                    $("#mergeFormDiv").close();
                    queryTable.reload(queryform.data());
                }
            }
        }
    });

    var queryTable = $("#queryTable").adpTable({
        url: '../rs/Ant/list',
        where: queryform.data(),
        cols: [[
            {field: 'id', title: 'ID', type: 'checkbox', width: 30, sort: true, fixed: 'left'},
            {field: 'ip', title: 'ip', width: 180},
            {field: 'connect', title: '接口', width: 120},
            {field: 'location', title: '工位', width: 200},
            {field: 'antType', title: '阅读器类型', width: 180},
            {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#OPERATION_ROW_TPL'}
        ]],
        methods: {
            edit: function edit(data, tr) {
                $("#mergeFormDiv").open("编辑天线");
                mergeForm.reset();
                mergeForm.data(data);
            },
            del: function del(data, tr) {
                layer.confirm('真的删除行么', function (index) {
                    SV("Ant")("delete")({ids: [data.id]});
                    queryTable.reload(queryform.data());
                    layer.close(index);
                });
            }
        }
    });

    function addEntity() {
        return $("#mergeFormDiv").open("添加阅读器", {
            success: function success() {
                return mergeForm.reset();
            }
        });
    };

    function deleteAllEntity(arr) {
        var _queryTable$checkStat = queryTable.checkStatus(),
            data = _queryTable$checkStat.data;
        var ids = new Array();
        $.each(data, function (n, value) {
            ids.push(value.id);
        });
        layer.confirm('真的删除行么', function (index) {
            Deferred("Ant")("delete")({
                "ids": ids
            })
            queryTable.reload(queryform.data());
            layer.close(index);
        });
    };
</script>